package com.xbfinance.manager.web;

import com.xbfinance.manager.pojo.dto.AdminPageParam;
import com.xbfinance.manager.pojo.dto.AdminPageResult;
import com.xbfinance.manager.pojo.dto.AdminSearch;
import com.xbfinance.manager.pojo.po.P2pAccountRecharge;
import com.xbfinance.manager.service.AdminRechargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class AdminRechargeController {
    @Autowired
    private AdminRechargeService adminRechargeService;
    //获取分页数据
    @RequestMapping(value="/adminListRecharge",method= RequestMethod.POST)
    @ResponseBody
    public AdminPageResult<P2pAccountRecharge> listRecharge(AdminPageParam page){
        AdminPageResult<P2pAccountRecharge> res = adminRechargeService.listRecharge(page);
        return res;
    }
    //审核通过
    @RequestMapping(value="/adminAgreeRecharge/{rid}",method=RequestMethod.PUT)
    @ResponseBody
    public Map<String,Boolean> adminAgreeRecharge(@PathVariable("rid") int rid){
        Map<String,Boolean> map = new HashMap<>();
        Boolean flag = false;
        int i = adminRechargeService.agreeRecharge(rid);
        if(i!=0){
            flag = true;
        }
        map.put("flag",flag);
        return map;
    }
    //审核拒绝
    @RequestMapping(value="/adminRejectRecharge/{rid}",method=RequestMethod.PUT)
    @ResponseBody
    public Map<String,Boolean> adminRejectRecharge(@PathVariable("rid") int rid){
        Map<String,Boolean> map = new HashMap<>();
        Boolean b = false;
        int i = adminRechargeService.adminRejectRecharge(rid);
        if(i!=0){
            b=true;
        }
        map.put("flag",b);
        return map;
    }
    //删除
    @RequestMapping(value="/removeRechargeByRid/{rid}",method=RequestMethod.DELETE)
    @ResponseBody
    public Map<String,Boolean> removeRechargeByRid(@PathVariable("rid") int rid){
        Map<String,Boolean> map = new HashMap<>();
        Boolean b = false;
        int i = adminRechargeService.removeRechargeByRid(rid);
        if(i!=0){
            b = true;
        }
        map.put("flag",b);
        return map;
    }
    //查询
    @RequestMapping(value="/searchRecharge",method=RequestMethod.POST)
    @ResponseBody
    public AdminPageResult<P2pAccountRecharge> searchRecharge(AdminPageParam page,AdminSearch as){
        AdminPageResult<P2pAccountRecharge> res = adminRechargeService.searchRecharge(page,as);
        return res;
    }
    //批量删除
    @RequestMapping(value="/adminRemoves",method=RequestMethod.POST)
    @ResponseBody
    public Map<String,Boolean> adminRemoves(@RequestParam("ids[]") List<Integer> list){
        Map<String,Boolean> map = new HashMap<>();
        Boolean b = false;
        int i = adminRechargeService.adminRemoves(list);
        if(i!=0){
            b=true;
        }
        map.put("flag",b);
        return map;
    }




}
